package edu.njfu.myapplication

fun main(){
    val p1=Person2();
    //p1=Person2();
    p1.name="张三";
    p1.eat();
    val stu1=Student9("zhangsan",19);
    stu1.doHomeWork();
    stu1.readBook();
    //创建数据类
    var stu2=Student10(1,"李四",18,"男");
    println(stu2.toString())
    //单例模式测试
    Singleton.singletonTest();
}
open class  Person2{
    var name:String="";
    var age:Int=0;

    fun eat():Unit{
       println(name +"正在吃东西");
        //println("$name正在吃东西");
    }

}
class Student8:Person2(){
    var stuno="";
    var grade=1;
}
//接口
//interface
interface  Study2{
    /**
     * 接口中只允许有函数，不能有常量
     * 在接口中，函数只有声明(declaration)，没有定义(definition)
     * 在此处定义就是implement
     *
     */
    fun readBook():Unit;
    fun doHomeWork():Unit;
}
class Student9(var name:String,var age:Int):Study2{
    override fun readBook() {
        println("$name is reading book!");
    }

    override fun doHomeWork() {
        println("$name is doing homework!");
    }

}
//data class
data class Student10(var stuno:Int,var stuName:String,var age:Int,
                     var sex:String);
//object,相当于java中的静态方法
object Singleton{
    fun singletonTest(){
        println("singleton Test is called");
    }
}
/*
   java 单例模式
   class SingleTon{
        private SingleTon singleTon;
        //把构造方法变为私有的
        private SingleTon(){}
        public Singleton getInstance(){
            if(singleTon!=null)
                return singleTon;
             else{
                singleTon=new SingleTon();
                return singleTon;
             }
       }
    }


   }
 */
